package com.yijinsuo.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yijinsuo.R;

/**
 * Created by ekikousei易皇星 on 16/11/17.
 * E-mail:13764664731@163.com
 * Signature:缘分是本书,翻的不经意会错过,读的太认真会流泪!!
 * <p/>
 * TODO:类描述:
 */
public class MainTitleBar extends LinearLayout {
    private View view;
    private RelativeLayout titlebar_rl_bag_color;
    private TextView titlebar_tv_center_text;
    private ImageView titlebar_iv_back,titlebar_iv_rignt_img;
    public MainTitleBar(Context context) {
        super(context);
        init(context);
    }

    public MainTitleBar(Context context, AttributeSet attrs) {
        super(context, attrs);
        view= LayoutInflater.from(context).inflate(R.layout.miantitle_layout, this, true);
        init(context);
    }

    private void init(Context context) {


        titlebar_rl_bag_color= (RelativeLayout) view.findViewById(R.id.titlebar_rl_bag_color);

        titlebar_tv_center_text= (TextView) view.findViewById(R.id.titlebar_tv_center_text);


        titlebar_iv_back= (ImageView) view.findViewById(R.id.titlebar_iv_back);

        titlebar_iv_rignt_img= (ImageView) view.findViewById(R.id.titlebar_iv_rignt_img);


    }

    /**
     *
     * @param msg 设置文本,和事件监听
     */
    public void setTitleBarCenterText(String msg,View.OnClickListener mlistener){
        titlebar_tv_center_text.setText(msg);
        titlebar_iv_back.setOnClickListener(mlistener);


    }

    /**
     *
     * @param color  设置titlebar 背景颜色
     */
    public void setTitleBarBackgroundColor(int color){
        titlebar_rl_bag_color.setBackgroundColor(color);
    }

    /**
     *
     * @param imageBack
     * @param centerMesg
     * @param imageRight
     */
    public  void setTitleBar(int imageBack,String centerMesg,int imageRight){
        titlebar_iv_back.setImageResource(imageBack);
        titlebar_tv_center_text.setText(centerMesg);
        titlebar_iv_rignt_img.setImageResource(imageRight);


    }

    public void setTitleBarTextColor(int color){
        titlebar_tv_center_text.setTextColor(color);
    }

    /**
     *
     * @param mlicklistener  事件监听
     */
    public void setTitleBarLeftListener(View.OnClickListener mlicklistener){
        titlebar_iv_back.setOnClickListener(mlicklistener);
        titlebar_iv_rignt_img.setOnClickListener(mlicklistener);

    }

}
